/*
 * LDIR
 * 
 * LDIR, a GPS cartography application built for Let's Do It Romania eco 
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 * 
 * http://generasoftware.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#include <e32base.h>
#include <e32std.h>
#include <lbs.h>
#include <e32math.h>
#include "GPSPositionData.h"

CGPSPositionData::CGPSPositionData() :
	iIsValid( EFalse )
	{
	}

CGPSPositionData::~CGPSPositionData()
	{
	}

CGPSPositionData* CGPSPositionData::NewLC()
	{
	CGPSPositionData* self = new ( ELeave ) CGPSPositionData();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}

CGPSPositionData* CGPSPositionData::NewL()
	{
	CGPSPositionData* self = CGPSPositionData::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CGPSPositionData::ConstructL()
	{
	}

void CGPSPositionData::Init()
	{
	TRealX realNaN;
	realNaN.SetNaN();

	iIsValid = EFalse;
	iPosition = TPosition();
	iPositionModuleInfo = TPositionModuleInfo();
	realNaN.GetTReal( iHorizontalSpeed );
	realNaN.GetTReal( iTrueCourse );
	realNaN.GetTReal( iMagneticCourse );
	realNaN.GetTReal( iHeading );
	realNaN.GetTReal( iMagneticHeading );
	iSatelliteNumInView = 0;
	iSatelliteNumUsed = 0;
	}

void CGPSPositionData::SetPositionInfoL(
	TPositionModuleInfo aPositionModuleInfo,
	HPositionGenericInfo* aPositionInfo )
	{
	TBool flag( EFalse );
	TInt err( KErrNone );

	Init();
	iIsValid = ETrue;
	aPositionInfo->GetPosition( iPosition );
	iPositionModuleInfo = aPositionModuleInfo;
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldHorizontalSpeed );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldHorizontalSpeed,
			iHorizontalSpeed );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldTrueCourse );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldTrueCourse, iTrueCourse );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldMagneticCourse );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldMagneticCourse,
			iMagneticCourse );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldHeading );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldHeading, iHeading );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldMagneticHeading );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldMagneticHeading,
			iMagneticHeading );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldSatelliteNumInView );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldSatelliteNumInView,
			iSatelliteNumInView );
		}
	flag = aPositionInfo->IsFieldAvailable( EPositionFieldSatelliteNumUsed );
	if ( flag )
		{
		err = aPositionInfo->GetValue( EPositionFieldSatelliteNumUsed,
			iSatelliteNumUsed );
		}
	}

void CGPSPositionData::SetPositionInfoL( CGPSPositionData* aPositionInfo )
	{
	iIsValid = aPositionInfo->IsValid();
	iPosition = aPositionInfo->Position();
	iPositionModuleInfo = aPositionInfo->PositionModuleInfo();
	iHorizontalSpeed = aPositionInfo->HorizontalSpeed();
	iTrueCourse = aPositionInfo->TrueCourse();
	iMagneticCourse = aPositionInfo->MagneticCourse();
	iHeading = aPositionInfo->Heading();
	iMagneticHeading = aPositionInfo->MagneticHeading();
	iSatelliteNumInView = aPositionInfo->SatelliteNumInView();
	iSatelliteNumUsed = aPositionInfo->SatelliteNumUsed();
	}

TBool CGPSPositionData::IsValid() const
	{
	return iIsValid;
	}

TPosition CGPSPositionData::Position() const
	{
	return iPosition;
	}

TPositionModuleInfo CGPSPositionData::PositionModuleInfo() const
	{
	return iPositionModuleInfo;
	}

TReal32 CGPSPositionData::HorizontalSpeed() const
	{
	return iHorizontalSpeed;
	}

TReal32 CGPSPositionData::TrueCourse() const
	{
	return iTrueCourse;
	}

TReal32 CGPSPositionData::MagneticCourse() const
	{
	return iMagneticCourse;
	}
TReal32 CGPSPositionData::Heading() const
	{
	return iHeading;
	}
TReal32 CGPSPositionData::MagneticHeading() const
	{
	return iMagneticHeading;
	}

TInt8 CGPSPositionData::SatelliteNumInView() const
	{
	return iSatelliteNumInView;
	}

TInt8 CGPSPositionData::SatelliteNumUsed() const
	{
	return iSatelliteNumUsed;
	}

